home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / textdt / textdt_example.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-16  |  4.7 KB  |  160 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // AudioDT Example
  3. // 6.16.96 Deryk Robosson
  4. // The TextDT supports word selection as well as up/down scrolling w/mouse =)
  5.  
  6. //////////////////////////////////////////////////////////////////////////////
  7. // Includes
  8. #include "aframe:include/amigaapp.hpp"
  9. #include "aframe:include/window.hpp"
  10. #include "aframe:include/rect.hpp"
  11. #include "aframe:include/button.hpp"
  12. #include "aframe:include/reqtools.hpp"
  13. #include "aframe:include/textdt.hpp"
  14.  
  15. #include <workbench/startup.h>
  16. #include <workbench/workbench.h>
  17.  
  18. #include <utility/tagitem.h>
  19. #include <proto/utility.h>
  20. #include <clib/utility_protos.h>
  21. #include <pragmas/utility_pragmas.h>
  22.  
  23. //////////////////////////////////////////////////////////////////////////////
  24. // DisplayWindow Class Definition
  25.  
  26. class DisplayWindow : public AFWindow
  27. {
  28.     virtual void OnCloseWindow(LPIntuiMessage imess);
  29.     virtual void OnGadgetUp(LPIntuiMessage imess);
  30.     virtual void OnIDCMPUpdate(LPIntuiMessage imess);
  31.     virtual void DestroyWindow();
  32.     virtual ULONG WindowFlags();
  33.     virtual ULONG WindowIDCMP();
  34. };
  35.  
  36. void DisplayWindow::OnCloseWindow(LPIntuiMessage imess) // time to leave!! ;)
  37. {
  38.     DisplayWindow::DestroyWindow();
  39. }
  40.  
  41. void DisplayWindow::DestroyWindow()
  42. {
  43.     AFWindow::DestroyWindow();
  44.     delete this;
  45. }
  46. ULONG DisplayWindow::WindowFlags()
  47. {
  48.     return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
  49. }
  50.  
  51. ULONG DisplayWindow::WindowIDCMP()  // We need the IDCMP_IDCMPUPDATE for the TextDT Class
  52. {                                   // if we are to recieve messages for it =)
  53.     return (AFWindow::WindowIDCMP() | IDCMP_IDCMPUPDATE | IDCMP_GADGETDOWN);
  54. }
  55.  
  56. void DisplayWindow::OnGadgetUp(LPIntuiMessage imess)
  57. {
  58.     switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  59.  
  60.     case 100:   // TextDT Object
  61. //        ::RefreshGadgets(m_pWindow->FirstGadget,m_pWindow,(struct Requester*)NULL);
  62.         // Do whatever else here 8)
  63.         break;
  64.     default:
  65.         break;
  66.     }
  67. }
  68.  
  69. void DisplayWindow::OnIDCMPUpdate(LPIntuiMessage imess)
  70. {
  71.     AFReqTools rt;
  72.     char *buffer;
  73.     struct TagItem  *attrs;
  74.     struct TagItem  *tag;
  75.  
  76.     attrs=(struct TagItem*)imess->IAddress;
  77.  
  78.     if(tag=FindTagItem(DTA_Busy, attrs)) { // Check for busy attribute
  79.         if(tag->ti_Data)
  80.             SetWindowPointer(m_pWindow,WA_BusyPointer,TRUE,WA_PointerDelay,TRUE,TAG_DONE);
  81.         else
  82.             SetWindowPointer(m_pWindow,WA_Pointer,NULL,TAG_DONE);
  83.     }
  84. /*    if(tag=FindTagItem(TDTA_WordSelect, attrs)) { // Check for a word selected
  85.         if(tag->ti_Data) {
  86.             sprintf(buffer,"%s",tag->ti_Data);
  87.             rt.EZRequest(buffer,"Ok");
  88.         }
  89.     }*/
  90.     if(tag=FindTagItem(DTA_Sync,attrs)) // Check for a resync request
  91.         ::RefreshGadgets(m_pWindow->FirstGadget,m_pWindow,(struct Requester*)NULL);
  92. }
  93.  
  94. //////////////////////////////////////////////////////////////////////////////
  95. // ControlWindow Class Definition
  96.  
  97. class ControlWindow : public AFWindow
  98.  
  99. {
  100. public:
  101.     virtual void OnGadgetUp(LPIntuiMessage imess);
  102.  
  103.     AFButton    load;
  104.     AFReqTools  rt;
  105.     AFTextDT    text;
  106.     DisplayWindow *display;
  107. };
  108.  
  109. //////////////////////////////////////////////////////////////////////////////
  110. // ControlWindow Implementation routines
  111.  
  112. void ControlWindow::OnGadgetUp(LPIntuiMessage imess)
  113. {
  114.   AFRect rect;
  115.  
  116.   switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  117.  
  118.   case 100:     // Load button
  119.     if(!(rt.FileRequest())) {
  120.         rt.EZRequest("No dir/filename was entered","Ok");
  121.         break;
  122.     }
  123.     if(!(text.LoadText((char*)rt.GetFileName(),(struct Screen*)NULL))) {
  124.         rt.EZRequest("Load File Failed","Ok");
  125.         break;
  126.     }
  127.     display=new DisplayWindow;  // Create a new displaywindow
  128.     text.m_dtGlobal.dtWindow=display;   // Set the TextDT window equal to our new window
  129.     rect.SetRect(0,0,640,440);          // Set our new window size and position
  130.     display->Create(m_papp,&rect);      // Create new window
  131.     display->SetWindowTitles((UBYTE*)rt.GetFileName(),(UBYTE*)NULL);    // Set window title same as filename
  132.     rect.SetRect(0,0,640,440);          // Set size and position of TextDT
  133.     text.AddObject(display,&rect, 100); // Add object to our new window  with the gadid of 100, 
  134.                                         // we could use this in a OnGadgetUp/Down for our new displaywindow
  135.     break;
  136.   default:
  137.     AFWindow::OnGadgetUp(imess);
  138.     break;
  139.   }
  140. }
  141.  
  142. //////////////////////////////////////////////////////////////////////////////
  143. // MAIN
  144.  
  145. void main()
  146. {
  147.     AFAmigaApp theApp;
  148.     ControlWindow win;
  149.     AFRect rect(10,10,410,310);
  150.  
  151.     win.Create(&theApp,&rect,"AFrame TextDT Example");
  152.  
  153.     rect.SetRect(10,10,50,50);
  154.     win.load.Create("Load",&win,&rect,100);
  155.  
  156.     win.RefreshGadgets();
  157.  
  158.     theApp.RunApp();
  159. }
  160.